<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends Authenticated{
	
	function __construct() {
		parent::__construct();
		$this->load->model('user_model','usr');
	}
	
	function index(){
		$this->disp_profil();
	}
	
	function disp_profil(){
		$data_profil = $this->usr->get_user($this->session->userdata('nim'));
		$this->load->view('template/view_header');
		$this->load->view('template/view_menu');
		$this->load->view('home/show_profil',$data_profil);
		$this->load->view('template/view_footer');
	}
	
	function edit_profil(){
		$data_profil = $this->usr->get_user($this->session->userdata('nim'));
		$this->load->view('template/view_header');
		$this->load->view('template/view_menu');
		$this->load->view('home/edit_form',$data_profil);
		$this->load->view('template/view_footer');
	}
	
	function edit_process(){
		$data['nim']=$this->input->post('nim',TRUE);
		$data['nama']=$this->input->post('nama',TRUE);
		$data['email']=$this->input->post('email',TRUE);
		$data['nohp']=$this->input->post('nohp',TRUE);
		$this->usr->update_user($data);
		redirect(HOME);
	}
	
	function ubah_password(){
		$data['flash'] = $this->session->flashdata('error');
		$this->load->view('template/view_header');
		$this->load->view('template/view_menu');
		$this->load->view('home/ubah_password',$data);
		$this->load->view('template/view_footer');
	}
	
	function ubah_password_process(){
		$data_profil = $this->usr->get_user($this->session->userdata('nim'));
		$old_pwd = $this->input->post('old_password',TRUE);
		$new_pwd = $this->input->post('new_password_1',TRUE);
		if($data_profil['password']!=md5($old_pwd)){
			$this->session->set_flashdata('error',TRUE);
			redirect(HOME.'ubah_password');
		}else{
			$data['nim']=$this->session->userdata('nim');
			$data['password']=md5($new_pwd);
			$this->usr->update_user($data);
			redirect(HOME);
		}
	}
	
	function upload_foto(){
		$this->load->view('template/view_header');
		$this->load->view('template/view_menu');
		$this->load->view('home/foto_form');
		$this->load->view('template/view_footer');
	}	
	
	function foto_process(){
		$config['upload_path'] = './public/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '1000';
		$config['overwrite'] = TRUE;
		
		$this->load->library('upload', $config);
		
		$type = '.'.substr($_FILES['foto']['type'],6);
		$_FILES['foto']['name']='foto_'.$this->session->userdata('nim').$type;
		
		$this->upload->do_upload('foto');
		$data_foto = $this->upload->data();
		
		$data['foto']=UPLOAD.$data_foto['file_name'];
		$data['nim']=$this->session->userdata('nim');
		
		$this->usr->update_user($data);
		redirect(HOME);
		
	}
	
	
	function upload_transkrip(){
		$this->load->view('template/view_header');
		$this->load->view('template/view_menu');
		$this->load->view('home/transkrip_form');
		$this->load->view('template/view_footer');
	}
	
	function transkrip_process(){
		$config['upload_path'] = './public/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size'] = '1000';
		$config['overwrite'] = TRUE;
		
		$this->load->library('upload', $config);
		
		$type = '.'.substr($_FILES['transkrip']['type'],6);
		$_FILES['transkrip']['name']='transkrip_'.$this->session->userdata('nim').$type;
		
		$this->upload->do_upload('transkrip');
		$data_foto = $this->upload->data();
		
		$data['transkrip']=UPLOAD.$data_foto['file_name'];
		$data['nim']=$this->session->userdata('nim');
		
		$this->usr->update_user($data);
		redirect(HOME);
	}
}
/** End of file */
